package com.yulan.Array;

import org.junit.Test;

/**
 * 581. 最短无序连续子数组
 */
public class LeetCode_581 {

    public int findUnsortedSubarray(int[] nums) {
        int len = nums.length;
        int max = nums[0];
        int min = nums[len-1];
        int l = 0,r = -1;
        for(int i = 0;i<len;i++){
            if(max > nums[i])
                r = i;
            else
                max = nums[i];

            if(min < nums[len - i - 1])
                l = len - i - 1;
            else
                min = nums[len - i - 1];
        }
        return r - l + 1;
    }

    @Test
    public void test1(){
        int[] arr = {1};
        System.out.println(findUnsortedSubarray(arr));
    }
}
